package router

import (
	"github.com/kataras/iris/v12"
	"github.com/rs/cors"
	"iris_blog/router/admin"
	"iris_blog/router/web"
)

func NewRoter(app *iris.Application) {
	preSettring(app)
	// admin总路由地址
	adminParty := app.Party("/api/admin")
	admin.Upload(adminParty)
	admin.User(adminParty)
	admin.Article(adminParty)
	admin.Tag(adminParty)
	admin.Nav(adminParty)
	// web总路由地址
	webParty := app.Party("/api/web")
	web.Article(webParty)
	web.Focus(webParty)
	web.Nav(webParty)
	web.Setting(webParty)
	web.Tag(webParty)
}
func preSettring(app *iris.Application) () {

	// 解决跨域的主要代码
	c := cors.New(cors.Options{
		AllowedOrigins:   []string{"*"},
		AllowCredentials: true,
		AllowedHeaders:   []string{"*"},
		Debug:            true,
	})
	app.WrapRouter(c.ServeHTTP)

}
